package com.yun.algorithmproblem.leetcode;

public class Leetcode2216 {

    public int minDeletion(int[] nums) {
        int res = 0;
        int i=0;
        int j=1;
        while (j<nums.length){
            if(nums[i]==nums[j]){
                res++;
                j++;
            }else {
                i=j+1;
                j=i+1;
            }
        }
        if((nums.length-res)%2!=0){
            res++;
        }
        return res;
    }

    public int minDeletion1(int[] nums) {
        int n = nums.length;
        int ans = 0;
        boolean check = true;
        for (int i = 0; i + 1 < n; ++i) {
            if (nums[i] == nums[i + 1] && check) {
                ++ans;
            } else {
                check = !check;
            }
        }
        if ((n - ans) % 2 != 0) {
            ++ans;
        }
        return ans;
    }

    public static void main(String[] args) {
        int[] nums={1,1,1,2,3,3};
        int res=new Leetcode2216().minDeletion(nums);
        int res1=new Leetcode2216().minDeletion1(nums);
        System.out.println(res);
        System.out.println(res1);
    }
}
